package com.brooks;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * @author Maoyan
 * @data 2020/10/17 15:39
 * @Version 1.0.0
 */
@SuppressWarnings("all")
public class Main implements Runnable{
    private String url;
    private String name;

    public Main(String url, String name) {
        this.url = url;
        this.name = name;
    }

    //重写run方法
    public void run() {
        Download download = new Download();
        download.downloader(url,name);
        System.out.println("下载了文件"+name);
    }

    public static void main(String[] args) {
        //启动线程，同时运行
        Main main1 = new Main("https://static.easyicon.net/preview/117/1173942.gif","1.gif");
        Main main2 = new Main("http://www.javazx.com/template/xinyun_door_001/images/logo.png","2.jpg");
        Main main3 = new Main("https://static.easyicon.net/preview/117/1173826.gif","3.gif");
//        main1.start();
//        main2.start();
//        main3.start();
        new Thread(main1).start();
        new Thread(main2).start();
        new Thread(main3).start();

    }
}

class Download{
    public void downloader(String url,String name){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(name));

        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("出现错误");
        }
    }
}
